﻿/// <reference path="Controls/TimeCalculatorControl.js" />
// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
    "use strict";

    WinJS.Binding.optimizeBindingReferences = true;

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            
            args.setPromise(WinJS.UI.processAll());

            var submitElement = document.getElementById("options-button");
            submitElement.addEventListener("click", function () {
                var menu = document.getElementById("submit-options").winControl;
                menu.show();
            });

            //Calculate days
            var submitElement = document.getElementById("calcDays");
            submitElement.addEventListener("click", function () {
                var timeControl = new Controls.TimeCalculator();
                var diff = timeControl._getDayDifference();

                document.getElementById("output").innerText = diff;
            });

            //Calculate hours
            var submitElement = document.getElementById("calcHours");
            submitElement.addEventListener("click", function () {
                var timeControl = new Controls.TimeCalculator();
                var diff = timeControl._getTimeDifference();

                document.getElementById("output").innerText = diff;
            });

            //Calculate days and hours
            var submitElement = document.getElementById("calcDaysAndHours");
            submitElement.addEventListener("click", function () {
                var timeControl = new Controls.TimeCalculator();
                var diff = timeControl.getDayAndTimeDifference();

                document.getElementById("output").innerText = diff;
            });

            //Enable time
            var switchElement = document.getElementById("enableTime");
            switchElement.addEventListener("click", function () {
                var toggleSwitch = switchElement.winControl;

                var timeControl = new Controls.TimeCalculator();
                timeControl.showTimePicker(toggleSwitch.checked);
            });
        }
    };

    app.oncheckpoint = function (args) {
        // TODO: This application is about to be suspended. Save any state
        // that needs to persist across suspensions here. You might use the
        // WinJS.Application.sessionState object, which is automatically
        // saved and restored across suspension. If you need to complete an
        // asynchronous operation before your application is suspended, call
        // args.setPromise().
    };

    app.start();
})();
